#ifndef OEWALLETMANAGE_H
#define OEWALLETMANAGE_H

#include <QObject>
#include <QMap>
#include <QDebug>
class OEWalletManage : public QObject
{
    Q_OBJECT
public:
    explicit OEWalletManage(QObject *parent = 0);
public:

    struct stWalletInfo{
        QString absPath; // wallet root path
        QString seedAbsPath; // seed path
        QString name; // wallet name
        QString ekPubKey; // wallet key
        QString status; // wallet status
        QString author; // create wallet author
        QString crtTime; // wallet create time
#ifdef WALLET_NEED_LOGO
        QString logo;
        QString logo_hover;
        QString logo_pressed;
#endif
        bool operator ==(const stWalletInfo& wallet) {
//            if (!this->status.compare("隐藏")) {
//                return false;
//            }
            return (this->ekPubKey == wallet.ekPubKey);
        }

        stWalletInfo(const QString& _filepath = "",
                     const QString& _walletName = "",
                     const QString& _ekPubKey = "")
            :absPath(_filepath), name(_walletName),
                ekPubKey(_ekPubKey){}
    };

    typedef QList<stWalletInfo> OEWalletList;

Q_SIGNALS:

    /**
    * brief: emit load finshed signal
    */
    void sigLoaded(void);

//    /**
//    * brief: emit finshed signal
//    *        abs path modified
//    * param: wallet abs path
//    */
//    void sigFinshed(const QString& _walletPath = "");

//    /**
//    * brief: emit backup signal
//    * param: source wallet abs path
//    * param: dest wallet abs path
//    */
//    void sigBackup(const QString&, const QString&);

//    /**
//    * brief: emit delete signal
//    *        delete wallet
//    * param: wallet name
//    * param: wallet abs path
//    */
//    void sigDelete(const QString&, const QString&);

//    /**
//    * brief: emit create signal
//    *        enter create wallet page
//    */
//    void sigCreate(void);

//    /**
//    * brief: use folder restore wallet
//    * param: need restore wallet path
//    */
//    void sigRestoreFromFolder(const QString&);

//    /**
//    * brief: use cryptolalia restore wallet
//    */
//    void sigRestoreFromCryptolalia(void);


//    /**
//    * brief: wallet name modify
//    * param: old name
//    * param: new name
//    */
//    void sigWalletNameChange(const QString&, const QString&);

public:

    /**
    * brief: clear wallet
    */
    void clearWallet(void);

    /**
    * brief: load wallet
    * param: wallet folder abs path
    * return: load wallet count
    *         int < 0 load error
    */
    int loadWallet(const QString& _path);

    /**
    * brief: create wallet
    * param: info must contain (path name)
    */
    int createWallet(const stWalletInfo& _info);

    /**
     * brief: Through pub key get wallet info
     * param: wallet ekpubkey
     * return: about param1 wallet info
     *         failed return null
     */
    stWalletInfo getWalletInfo(const QString& _pubKey);


    const OEWalletList& getAllWallet(void);

    int size(void);
protected:

    /**
     * brief: load wallet info - name
     * param: wallet folder abs path
     * param: wallet struct   - out
     * return: 0 : success, not 0 : failed
    */
    int loadWalletInfo(const QString& _rootpath, stWalletInfo& _wallet);

    /**
    * brief: find wallet folder
    * param: wallet root directory path
    * return: list wallet abs path
    *         find wallet failed return list size = 0
    */
    QStringList findWallet(const QString& _path);
private:

    /**
    * brief: convert unknown path to abs path
    *        if _outpath is relative path
    *        convert _outpath to
    *        _outpath = _rootpath + _outpath;
    */
    bool convertPathToAbs(const QString& _rootPath,
                             QString &_outpath);

    /**
    * brief: create click image (hover and pressed)
    *        if (_logoHover || _logoPressed) is null
    *        create images based on _logo
    */
//    bool createPixmap(const QString& _logo,
//                      QString& _logoHover,
//                      QString& _logoPressed);

    /**
    * brief: check path is wallet folder
    * param: _path is wallet folder path
    * return: true is yes, false is no
    */
    bool isWallet(const QString& _path);


    /**
    * brief: create wallet menu
    * retuen: return menu
    */
    //QMenu* createWalletMenu(const stWalletInfo& _info);

protected Q_SLOTS:

    /**
    * brief: enter _absPath
    *        use _absPath become work path
    */
//    bool onHandoverWorkPath(const QString& _absPath);



private:

    OEWalletList listInfo_;

    QMap<QString, QString> mapFileName_;

    /// wallet root path;
    QString rootPath_;



};

#endif // OEWALLETMANAGE_H
